package com.open.capacity.dao;

import com.open.capacity.common.model.SttRole;
import com.open.capacity.common.model.SysRole;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;


/**
* @author 作者 owen 
* @version 创建时间：2017年11月12日 上午22:57:51
* 用户角色关系
 */
@Component
public interface SysUserRoleDao {

	int deleteUserRole(@Param("userId") Long userId, @Param("roleId") Long roleId);

	@Insert("insert into stt_role_user(straid, roleid) values(#{userId}, #{roleId})")
	int saveUserRoles(@Param("userId") Long userId, @Param("roleId") Long roleId);
	/**
	 * 根据用户id获取角色
	 * 
	 * @param userId
	 * @return
	 */
	@Select("select r.roleid id ,r.rocode code, r.roname name, r.crtime createTime  , r.uptime   updateTime  from stt_role_user ru inner join stt_role r on r.roleid = ru.roleid where ru.straid = #{userId}")
	Set<SttRole> findRolesByUserId(Long userId);

	/**
	 *  根据用户ids 获取
	 * @param userIds
	 * @return
	 */
 
	@Select("<script>select r.roleid id ,r.rocode code, r.roname name, r.crtime createTime  , r.uptime   updateTime ,ru.straid userId from stt_role_user ru inner join stt_role r on r.roleid = ru.roleid where ru.straid IN " +
			" <foreach item='item' index='index' collection='list' open='(' separator=',' close=')'> " +
			" #{item} " +
			" </foreach>" +
			"</script>")
	List<SttRole> findRolesByUserIds(List<Long> userIds);



}
